
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#include "RTMatrix33.h"

//constructor
RTMatrix33::RTMatrix33()
{
	m[0][0] = m[1][1] = m[2][2] = 1;
	m[0][1] = m[0][2] = m[1][0] = m[1][2] = m[2][0] = m[2][1]  = 0; 
}

//constructor using vector3f as columns
RTMatrix33::RTMatrix33(const CVector3f& c0, const CVector3f& c1, const CVector3f& c2)
{
	m[0][0] = c0.x;		m[0][1] = c1.x;		m[0][2] = c2.x;
	m[1][0] = c0.y;		m[1][1] = c1.y;		m[1][2] = c2.y;
	m[2][0] = c0.z;		m[2][1] = c1.z;		m[2][2] = c2.z;
}

//calculate the determinant
float RTMatrix33::det() const
{
	return	m[0][0]*m[1][1]*m[2][2] + 
			m[0][1]*m[1][2]*m[2][0] + 
			m[0][2]*m[1][0]*m[2][1] -
			m[0][2]*m[1][1]*m[2][0] - 
			m[0][1]*m[1][0]*m[2][2] -
			m[0][0]*m[1][2]*m[2][1];
}

//set the columns of the matrix to the vectors
void RTMatrix33::setColumns(const CVector3f& c0, const CVector3f& c1, const CVector3f& c2)
{
	m[0][0] = c0.x;		m[0][1] = c1.x;		m[0][2] = c2.x;
	m[1][0] = c0.y;		m[1][1] = c1.y;		m[1][2] = c2.y;
	m[2][0] = c0.z;		m[2][1] = c1.z;		m[2][2] = c2.z;
}